{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json\n",
    "import csv\n",
    "import random\n",
    "import re\n",
    "from datetime import datetime\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [],
   "source": [
    "# datenum = datetime.now().strftime('%Y%m%d%H%M')\n",
    "datenum= int((datetime.now()-datetime.strptime('1970-01-01 00:00:00','%Y-%m-%d %H:%M:%S')).total_seconds()*1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 479,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Referer': 'https://detail.m.tmall.com/item.htm?id=561852573443',\n",
       " 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'}"
      ]
     },
     "execution_count": 479,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "url = r'https://detail.m.tmall.com/item.htm?id=561852573443'\n",
    "# thatid = url[-12:]\n",
    "thatid = \"561852573443\"\n",
    "itemNumId = {\"itemNumId\":thatid}\n",
    "headers = { 'user-agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1',\n",
    "            'Referer': 'https://detail.m.tmall.com/item.htm?id=561852573443'}\n",
    "headers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 480,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.4.8&appKey=12574478&t=1531006042349&sign=c5aca960613336cd613ca342846fb95a&api=mtop.taobao.detail.getdetail&v=6.0&dataType=jsonp&ttid=2017%40taobao_h5_6.6.0&AntiCreep=true&type=jsonp&callback=mtopjsonp2&data=%7B%22itemNumId%22%3A%22561852573443%22%7D'"
      ]
     },
     "execution_count": 480,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_url =  '''https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?\\\n",
    "jsv=2.4.8&appKey=12574478&t={0}&sign=c5aca960613336cd613ca34284\\\n",
    "6fb95a&api=mtop.taobao.detail.getdetail&v=6.0&dataType=jsonp&ttid\\\n",
    "=2017%40taobao_h5_6.6.0&AntiCreep=true&type=jsonp&callback=mtopjs\\\n",
    "onp2&data=%7B%22itemNumId%22%3A%22{1}%22%7D'''.format(datenum, thatid)\n",
    "get_url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 481,
   "metadata": {},
   "outputs": [],
   "source": [
    "with requests.Session() as s:\n",
    "    r = s.get(url, headers=headers)\n",
    "    res = s.get(get_url, headers=headers, params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 482,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'初上市价格40元'"
      ]
     },
     "execution_count": 482,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_data = json.loads(res.text[11:-1])\n",
    "json_data['data']['item']['subtitle']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 483,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['apiStack', 'item', 'mockData', 'params', 'props', 'props2', 'rate', 'resource', 'seller', 'skuBase', 'vertical', 'weappData'])"
      ]
     },
     "execution_count": 483,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_data['data'].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 484,
   "metadata": {},
   "outputs": [],
   "source": [
    "# json_data['data']['item']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 485,
   "metadata": {},
   "outputs": [],
   "source": [
    "# json.loads(json_data['data']['mockData'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 486,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['2018年春季 ',\n",
       "  '聚酯纤维66% 棉15% 聚氨酯弹性纤维(氨纶)10% 聚酰胺纤维(锦纶)9% ',\n",
       "  '1条 ',\n",
       "  '聚酯纤维66% 棉15% 聚氨酯弹性纤维(氨纶)10% 聚酰胺纤维(锦纶)9% ',\n",
       "  '商场同款(线上线下都销售) ',\n",
       "  'UQ404040000 ',\n",
       "  '男 ',\n",
       "  '00 白色 04 烟灰色 07 青灰色 09 黑色 54 绿色 66 蓝色 69 藏青色 ',\n",
       "  '其他 ',\n",
       "  '165/90/S 170/95/M 175/100/L 180/105/XL ',\n",
       "  'Uniqlo/优衣库 '],\n",
       " [{'上市时间': '2018年春季 '},\n",
       "  {'大身材质成分': '聚酯纤维66% 棉15% 聚氨酯弹性纤维(氨纶)10% 聚酰胺纤维(锦纶)9% '},\n",
       "  {'条数': '1条 '},\n",
       "  {'裆部材质成分': '聚酯纤维66% 棉15% 聚氨酯弹性纤维(氨纶)10% 聚酰胺纤维(锦纶)9% '},\n",
       "  {'销售渠道类型': '商场同款(线上线下都销售) '},\n",
       "  {'款号': 'UQ404040000 '},\n",
       "  {'适用性别': '男 '},\n",
       "  {'颜色分类': '00 白色 04 烟灰色 07 青灰色 09 黑色 54 绿色 66 蓝色 69 藏青色 '},\n",
       "  {'材质': '其他 '},\n",
       "  {'尺码': '165/90/S 170/95/M 175/100/L 180/105/XL '},\n",
       "  {'品牌': 'Uniqlo/优衣库 '}])"
      ]
     },
     "execution_count": 486,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "  #基本信息\n",
    "def basic_info(json_data):\n",
    "    basic_info = json_data['data']['props']['groupProps'][0]['基本信息']\n",
    "    basic_value = []\n",
    "    for i in basic_info:\n",
    "        basic_value.append(list(i.values())[0])\n",
    "    return basic_value\n",
    "basic_info(json_data), json_data['data']['props']['groupProps'][0]['基本信息']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 487,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'男装 SUPIMA COTTON针织短裤(普通腰) 404040 优衣库UNIQLO'"
      ]
     },
     "execution_count": 487,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json_data['data']['item']['title']  #important"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 488,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https//gw.alicdn.com/bao/uploaded/i4/196993935/TB2OeWDeTnI8KJjSszbXXb4KFXa-196993935.jpg'"
      ]
     },
     "execution_count": 488,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sell_counts = json.loads(json_data['data']['apiStack'][0]['value'])\n",
    "'https'+sell_counts['skuBase']['props'][0]['values'][0]['image']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 489,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('10889',\n",
       " 'https://img.alicdn.com/imgextra/i3/196993935/TB1B5rAmByWBuNkSmFPXXXguVXa_!!0-item_pic.jpg')"
      ]
     },
     "execution_count": 489,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sell_counts['item']   #sellCount videoThumbnailURL\n",
    "def get_monsellcounts(json_data):\n",
    "    sell_counts = json.loads(json_data['data']['apiStack'][0]['value'])\n",
    "    sellCount = sell_counts['item']['sellCount']\n",
    "    try:\n",
    "        sell_img = sell_counts['item']['videos'][0]['videoThumbnailURL']\n",
    "    except IndexError as e:\n",
    "        sell_img = 'https'+sell_counts['skuBase']['props'][0]['values'][0]['image']\n",
    "    return sellCount, sell_img\n",
    "get_monsellcounts(json_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 464,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'extraPrices'",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-464-a0e1075f2f7f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[0moprice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msell_counts\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'price'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'extraPrices'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'priceText'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mtransmitPrice\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moprice\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mget_sell_price\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mjson_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m<ipython-input-464-a0e1075f2f7f>\u001b[0m in \u001b[0;36mget_sell_price\u001b[1;34m(json_data)\u001b[0m\n\u001b[0;32m      2\u001b[0m     \u001b[0msell_counts\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloads\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mjson_data\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'data'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'apiStack'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'value'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0mtransmitPrice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msell_counts\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'price'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'transmitPrice'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'priceText'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m     \u001b[0moprice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msell_counts\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'price'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'extraPrices'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'priceText'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mtransmitPrice\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moprice\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[0mget_sell_price\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mjson_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'extraPrices'"
     ],
     "output_type": "error"
    }
   ],
   "source": [
    "def get_sell_price(json_data):\n",
    "    sell_counts = json.loads(json_data['data']['apiStack'][0]['value'])\n",
    "    transmitPrice = sell_counts['price']['transmitPrice']['priceText']\n",
    "    oprice = sell_counts['price']['extraPrices'][0]['priceText']\n",
    "    return transmitPrice, oprice\n",
    "get_sell_price(json_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 468,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'price': {'priceText': '27', 'sugProm': 'false'},\n",
       " 'shopProm': [{'actionUrl': '//h5.m.taobao.com/shopb/shopactivity.html?activityId=6194195296&sellerId=196993935&source=2&spm=W-a211f8.10431435&scm=20140619.detail.dpb.0',\n",
       "   'activityId': '6194195296',\n",
       "   'content': ['满200元,享部分地区包邮'],\n",
       "   'iconText': '促销',\n",
       "   'period': '2018.06.15-2018.08.31',\n",
       "   'title': '满200元 免运费',\n",
       "   'type': '3',\n",
       "   'uuid4Cal': '6194195296'}],\n",
       " 'transmitPrice': {'priceText': '27', 'sugProm': 'false'}}"
      ]
     },
     "execution_count": 468,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sell_counts = json.loads(json_data['data']['apiStack'][0]['value'])\n",
    "sell_counts['price']['transmitPrice']['priceText']\n",
    "sell_counts['price']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 431,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'79'"
      ]
     },
     "execution_count": 431,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sell_counts['price']['price']['priceText']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 472,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('27',\n",
       " ' ',\n",
       " '1',\n",
       " 'https://gw.alicdn.com/bao/uploaded/i3/196993935/TB2.I7zCxSYBuNjSsphXXbGvVXa-196993935.jpg')"
      ]
     },
     "execution_count": 472,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_sell_price(json_data):\n",
    "    sell_counts = json.loads(json_data['data']['apiStack'][0]['value'])\n",
    "    transmitPrice = sell_counts['price']['transmitPrice']['priceText']\n",
    "    try:\n",
    "        oprice = sell_counts['price']['extraPrices'][0]['priceText']\n",
    "    except KeyError as e:\n",
    "        oprice = ' '\n",
    "    sellCount = sell_counts['item']['sellCount']\n",
    "    try:\n",
    "        sell_img = sell_counts['item']['videos'][0]['videoThumbnailURL']\n",
    "    except IndexError as e:\n",
    "        sell_img = 'https:'+sell_counts['skuBase']['props'][0]['values'][0]['image']\n",
    "    return transmitPrice, oprice, sellCount, sell_img\n",
    "get_sell_price(json_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 476,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('', '', '')"
      ]
     },
     "execution_count": 476,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_time_count(json_data):\n",
    "    try:\n",
    "        startTime = sell_counts['vertical']['jhs']['startTime']\n",
    "        endTime = sell_counts['vertical']['jhs']['endTime']\n",
    "        soldCount = sell_counts['vertical']['jhs']['soldCount']\n",
    "    except KeyError as e:\n",
    "        startTime = endTime = soldCount = ''\n",
    "    return startTime, endTime, soldCount\n",
    "get_time_count(json_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 475,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'buyer': {'tmallMemberLevel': '0'},\n",
       " 'consumerProtection': {'items': [{'desc': '该商品由中国人保承保正品保证险',\n",
       "    'serviceId': '3838',\n",
       "    'title': '正品保证',\n",
       "    'type': '0'},\n",
       "   {'desc': '不支持7天退换', 'serviceId': '3521', 'title': '不支持7天退换', 'type': '0'},\n",
       "   {'desc': '极速退款是为诚信会员提供的退款退货流程的专享特权，额度是根据每个用户当前的信誉评级情况而定',\n",
       "    'serviceId': '2979',\n",
       "    'title': '极速退款',\n",
       "    'type': '0'}],\n",
       "  'params': '155:3838,3521,2979',\n",
       "  'passValue': 'none',\n",
       "  'strength': 'normal'},\n",
       " 'debugData': {},\n",
       " 'delivery': {'addressWeexUrl': '//market.m.taobao.com/apps/market/detailrax/address-picker.html?spm=a2116h.app.0.0.16d957e9nDYOzv&wh_weex=true',\n",
       "  'areaId': '442000',\n",
       "  'areaSell': 'true',\n",
       "  'completedTo': '广东省 中山市',\n",
       "  'from': '上海',\n",
       "  'overseaContraBandFlag': 'false',\n",
       "  'postage': '快递: 10.00',\n",
       "  'to': '中山市'},\n",
       " 'extendedData': {},\n",
       " 'feature': {'bSeller': 'true',\n",
       "  'bundleItem': 'false',\n",
       "  'cainiaoNoramal': 'true',\n",
       "  'fmcgRecommend': 'false',\n",
       "  'hasAddCartCoudan': 'false',\n",
       "  'hasAddTmallCartCoudan': 'false',\n",
       "  'hasApparelIcon': 'false',\n",
       "  'hasBrandScene': 'false',\n",
       "  'hasCartRecommend': 'false',\n",
       "  'hasCombo': 'false',\n",
       "  'hasCoupon': 'false',\n",
       "  'hasIntervalPrice': 'true',\n",
       "  'hasMeal': 'false',\n",
       "  'hasNewCombo': 'false',\n",
       "  'hasQualification': 'false',\n",
       "  'hasSeat': 'false',\n",
       "  'hasSku': 'true',\n",
       "  'hideSMww': 'false',\n",
       "  'hideShopDsr': 'false',\n",
       "  'hotItem': 'false',\n",
       "  'includeSkuData': 'true',\n",
       "  'isCloudChanger': 'false',\n",
       "  'isDamai': 'false',\n",
       "  'isDonateItem': 'false',\n",
       "  'isTspace': 'false',\n",
       "  'isVirtualRechargeItem': 'false',\n",
       "  'isXinxuan': 'false',\n",
       "  'makeup': 'false',\n",
       "  'multistage': 'false',\n",
       "  'nabundleItem': 'false',\n",
       "  'newAddress': 'true',\n",
       "  'noShareGroup': 'true',\n",
       "  'notUseVip95CardBar': 'false',\n",
       "  'o2O': 'false',\n",
       "  'open618RedbagH5url': 'false',\n",
       "  'open618RedbagPoplayer': 'false',\n",
       "  'openGradient': 'true',\n",
       "  'pricedCoupon': 'false',\n",
       "  'recommendReason': 'false',\n",
       "  'renovation': 'false',\n",
       "  'sellCountAntiCreep': 'true',\n",
       "  'shareGroup': 'false',\n",
       "  'showCommonBanner': 'false',\n",
       "  'showCuntaoTag': 'false',\n",
       "  'showNewPersonBag': 'false',\n",
       "  'showSMww': 'false',\n",
       "  'showShopCard': 'false',\n",
       "  'showSku': 'true',\n",
       "  'showSkuThumbnail': 'false',\n",
       "  'showTmallApp': 'false',\n",
       "  'showYaoDai': 'false',\n",
       "  'superActTime': 'false',\n",
       "  'switchToOldApp': 'false',\n",
       "  'useMeiLiHuiPrice': 'false',\n",
       "  'useVip95CardStyle': 'false',\n",
       "  'waitForStart': 'false'},\n",
       " 'item': {'descType': '2',\n",
       "  'infoText': {},\n",
       "  'itemId': '573188926280',\n",
       "  'itemPoint': '13',\n",
       "  'sellCount': '1',\n",
       "  'skuText': '配送至:中山市,请选择颜色分类/尺码',\n",
       "  'title': '男装 SUPIMA COTTON袜子 406398 优衣库UNIQLO',\n",
       "  'titleIcon': '//gw.alicdn.com/tps/i1/T1AV5DFSRbXXbaUxfe-36-32.png',\n",
       "  'videos': []},\n",
       " 'layout': {'config': {'dependActionConfigID': 'TB1CKiJk4WYBuNjy1zkhA0GGpXa',\n",
       "   'dependComponentConfigID': 'TB166Osa5IRMeJjy0FbhA2nqXXa',\n",
       "   'dependThemeConfigID': 'TB1O1LwiCCWBuNjy0FhhA26EVXa'},\n",
       "  'layoutId': 'TB1CqubkY1YBuNjSszehA1blFXa',\n",
       "  'templateDBId': '2027'},\n",
       " 'modules': [],\n",
       " 'otherInfo': {'bucketId': '12', 'systemTime': '1531023378858'},\n",
       " 'params': {'trackParams': {'abtest': '',\n",
       "   'aliBizCode': 'ali.china.tmall',\n",
       "   'aliBizToken': 'YWxpLmNoaW5hLnRtYWxs',\n",
       "   'bizParams': 'shopActivity_current',\n",
       "   'layoutId': '2027',\n",
       "   'shop_id': '57303596'}},\n",
       " 'price': {'price': {'priceText': '27', 'sugProm': 'false'},\n",
       "  'shopProm': [{'actionUrl': '//h5.m.taobao.com/shopb/shopactivity.html?activityId=6194195296&sellerId=196993935&source=2&spm=W-a211f8.10431435&scm=20140619.detail.dpb.0',\n",
       "    'activityId': '6194195296',\n",
       "    'content': ['满200元,享部分地区包邮'],\n",
       "    'iconText': '促销',\n",
       "    'period': '2018.06.15-2018.08.31',\n",
       "    'title': '满200元 免运费',\n",
       "    'type': '3',\n",
       "    'uuid4Cal': '6194195296'}],\n",
       "  'transmitPrice': {'priceText': '27', 'sugProm': 'false'}},\n",
       " 'rate': {},\n",
       " 'resource': {'coupon': {},\n",
       "  'entrances': {'recommendReason': None},\n",
       "  'promsCalcInfo': {'cheapestMoney': '0', 'hasCoupon': 'false'},\n",
       "  'redpacketList': [],\n",
       "  'share': {'iconType': '1',\n",
       "   'name': '分享',\n",
       "   'params': {'iconColor': '#999999', 'iconFont': 'ꄪ'}}},\n",
       " 'skuBase': {'props': [{'name': '颜色分类',\n",
       "    'pid': '1627207',\n",
       "    'values': [{'image': '//gw.alicdn.com/bao/uploaded/i3/196993935/TB2.I7zCxSYBuNjSsphXXbGvVXa-196993935.jpg',\n",
       "      'name': '03 灰色',\n",
       "      'sortOrder': '0',\n",
       "      'vid': '20753190'},\n",
       "     {'image': '//gw.alicdn.com/bao/uploaded/i1/196993935/TB2UworkiMnBKNjSZFoXXbOSFXa-196993935.jpg',\n",
       "      'name': '09 黑色',\n",
       "      'sortOrder': '2',\n",
       "      'vid': '8025988'}]},\n",
       "   {'name': '尺码',\n",
       "    'pid': '20509',\n",
       "    'values': [{'name': '均码', 'sortOrder': '1', 'vid': '28383'}]}],\n",
       "  'skus': [{'propPath': '1627207:20753190;20509:28383',\n",
       "    'skuId': '3902639026814'},\n",
       "   {'propPath': '1627207:8025988;20509:28383', 'skuId': '3902639026815'}]},\n",
       " 'skuCore': {'sku2info': {'0': {'price': {'priceMoney': '2700',\n",
       "     'priceText': '27',\n",
       "     'showTitle': 'false',\n",
       "     'sugProm': 'false'},\n",
       "    'quantity': '208',\n",
       "    'quantityText': '有货'},\n",
       "   '3902639026814': {'price': {'priceMoney': '2700',\n",
       "     'priceText': '27',\n",
       "     'showTitle': 'false',\n",
       "     'sugProm': 'false'},\n",
       "    'quantity': '208',\n",
       "    'quantityText': '有货'},\n",
       "   '3902639026815': {'price': {'priceMoney': '2700',\n",
       "     'priceText': '27',\n",
       "     'showTitle': 'false',\n",
       "     'sugProm': 'false'},\n",
       "    'quantity': '0',\n",
       "    'quantityText': '无货'}},\n",
       "  'skuItem': {'hideQuantity': 'false',\n",
       "   'location': '中山市',\n",
       "   'showAddress': 'true'}},\n",
       " 'skuVertical': {},\n",
       " 'traceDatas': {'dinamic+TB_detail_ask_all_aliMedical': {'module': 'tb_detail_ask_all_aliMedical'},\n",
       "  'dinamic+TB_detail_ask_all_no_question': {'module': 'tb_detail_ask_all_no_question'},\n",
       "  'dinamic+TB_detail_ask_all_two_questions': {'module': 'tb_detail_ask_all_two_questions'},\n",
       "  'dinamic+TB_detail_brand_info': {'module': 'tb_detail_brand_info'},\n",
       "  'dinamic+TB_detail_buyer_photo': {'module': 'tb_detail_buyer_photo'},\n",
       "  'dinamic+TB_detail_comment_empty': {'module': 'tb_detail_comment_empty'},\n",
       "  'dinamic+TB_detail_comment_head': {'module': 'tb_detail_comment_head'},\n",
       "  'dinamic+TB_detail_comment_single_hot': {'module': 'tb_detail_comment_single_hot'},\n",
       "  'dinamic+TB_detail_comment_tag': {'module': 'tb_detail_comment_tag'},\n",
       "  'dinamic+TB_detail_coupon': {'module': 'tb_detail_coupon'},\n",
       "  'dinamic+TB_detail_delivery': {'module': 'tb_detail_delivery'},\n",
       "  'dinamic+TB_detail_endorsement': {'module': 'tb_detail_endorsement'},\n",
       "  'dinamic+TB_detail_guarantee': {'module': 'tb_detail_guarantee'},\n",
       "  'dinamic+TB_detail_kernel_params': {'module': 'tb_detail_kernel_params'},\n",
       "  'dinamic+TB_detail_logistics': {'module': 'tb_detail_logistics'},\n",
       "  'dinamic+TB_detail_new_person_bag_banner': {'module': 'tb_detail_new_person_bag_banner'},\n",
       "  'dinamic+TB_detail_price_coupon': {'module': 'tb_detail_price_coupon'},\n",
       "  'dinamic+TB_detail_priced_coupon': {'module': 'tb_detail_priced_coupon'},\n",
       "  'dinamic+TB_detail_ship_time': {'module': 'tb_detail_ship_time'},\n",
       "  'dinamic+TB_detail_subInfo_jhs_normal': {'module': 'tb_detail_subInfo_jhs_normal'},\n",
       "  'dinamic+TB_detail_subInfo_preSellForTaobaoB': {'module': 'tb_detail_subInfo_preSellForTaobaoB'},\n",
       "  'dinamic+TB_detail_subInfo_preSellForTaobaoC': {'module': 'tb_detail_subInfo_preSellForTaobaoC'},\n",
       "  'dinamic+TB_detail_subInfo_superMarket': {'module': 'tb_detail_subInfo_superMarket'},\n",
       "  'dinamic+TB_detail_sub_logistics': {'module': 'tb_detail_sub_logistics'},\n",
       "  'dinamic+TB_detail_tax': {'module': 'tb_detail_tax'},\n",
       "  'dinamic+TB_detail_tip_presale': {'module': 'tb_detail_tip_presale'},\n",
       "  'dinamic+TB_detail_tip_presale2': {'module': 'tb_detail_tip_presale2'},\n",
       "  'dinamic+TB_detail_tip_price': {'module': 'tb_detail_tip_price'},\n",
       "  'dinamic+TB_detail_title_tmallMarket': {'module': 'tb_detail_title_tmallMarket'},\n",
       "  'dinamic+TB_detail_title_xinxuan': {'module': 'tb_detail_title_xinxuan'},\n",
       "  'dinamic+TB_detail_tmallfeature': {'module': 'tb_detail_tmallfeature'},\n",
       "  'dinamic+TB_detail_trade_guarantee': {'module': 'tb_detail_trade_guarantee'},\n",
       "  'dinamic_o2o+TB_detail_o2o': {'module': 'TB_detail_o2o'}},\n",
       " 'trade': {'buyEnable': 'true',\n",
       "  'buyParam': {'areaId': '442000'},\n",
       "  'cartConfirmEnable': 'true',\n",
       "  'cartEnable': 'true',\n",
       "  'cartParam': {'areaId': '442000'},\n",
       "  'isWap': 'false',\n",
       "  'tradeParams': {},\n",
       "  'tradeType': '2',\n",
       "  'useWap': 'false'},\n",
       " 'vertical': {'askAll': {'askIcon': 'https://img.alicdn.com/tps/TB1tVU6PpXXXXXFaXXXXXXXXXXX-102-60.png',\n",
       "   'askText': '宝贝好不好，问问已买的人',\n",
       "   'linkUrl': '//h5.m.taobao.com/wendajia/question2017.html?refId=573188926280',\n",
       "   'questNum': '0',\n",
       "   'title': '问大家'},\n",
       "  'cuntao': {},\n",
       "  'freshFood': {'nationalFlag': '//g.alicdn.com/mui/flag-img/circle@2x/CN.png'},\n",
       "  'vipComment': {}}}"
      ]
     },
     "execution_count": 475,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sell_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_file(self):\n",
    "        '''创建一个含有标题的表格'''\n",
    "        title = ['item_id', 'subtitle', 'extraPrices', 'price', 'NowsoldCount', 'MonsoldCount',\n",
    "                 'title', 'time', 'sickness', '材质成分', '袖长', '货号', '销售渠道类型',\n",
    "                 '领型', '颜色', '尺码', '品牌', '版型', '适用场景', '基础风格', 'url',\n",
    "                 'commentCount', 'img', 'startTime', 'endTime']\n",
    "        with open(self.filename,'w',newline='') as f:\n",
    "            writer = csv.DictWriter(f,fieldnames=title)\n",
    "            writer.writeheader()\n",
    "        return 'ok'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
